package com.yuexiang.melodyhub.authserver.handler;

import com.yuexiang.melodyhub.authserver.handler.context.RegisterContext;
import com.yuexiang.melodyhub.common.constant.UsualConstant.BizCodeConstant;
import com.yuexiang.melodyhub.common.exception.RequestArgumentException;
import com.yuexiang.melodyhub.common.handler.AbstractValidationHandler;
import com.yuexiang.melodyhub.common.utils.PasswordUtil;
import org.springframework.stereotype.Component;

@Component
public class PasswordValidationHandler extends AbstractValidationHandler<RegisterContext> {
    @Override
    public void handler(RegisterContext content) {
        if (!PasswordUtil.validatePassword(content.getOAuthRegisterParam().getPassword()))
            throw new RequestArgumentException(BizCodeConstant.Msg.PASSWORD_IS_INVALID);
        if (!content.getOAuthRegisterParam().getPassword().equals(content.getOAuthRegisterParam().getRepeatPass()))
            throw new RequestArgumentException(BizCodeConstant.Msg.REPEAT_PASSWORD_IS_INVALID);
        handlerNext(content);
    }
}
